$(function () {


    var lang = {
        "sProcessing": "处理中...",
        "sLengthMenu": "每页 _MENU_ 项",
        "sZeroRecords": "没有匹配结果",
        "sInfo": "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
        "sInfoEmpty": "当前显示第 0 至 0 项，共 0 项",
        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
        "sInfoPostFix": "",
        "sSearch": "搜索:",
        "sUrl": "",
        "sEmptyTable": "表中数据为空",
        "sLoadingRecords": "载入中...",
        "sInfoThousands": ",",
        "oPaginate": {
            "sFirst": "首页",
            "sPrevious": "上页",
            "sNext": "下页",
            "sLast": "末页",
            "sJump": "跳转"
        },
        "oAria": {
            "sSortAscending": ": 以升序排列此列",
            "sSortDescending": ": 以降序排列此列"
        }
    };

    var table = $('#example2').DataTable({
        language: lang,
        lengthMenu: [
            5, 10, 15, 30, 50
        ],
        // processing: true,
        // serverSide: true,
        // bInfo: false, //是否显示是否启用底边信息栏
        ajax: {
            url: "/teachers/tclasslist",
            type: 'GET',
            dataSrc: function (e) {
                // console.log(e)
                return e
            }
        },
        // data:data,
        autoWidth: true,
        // pagingType: 'full_numbers',
        columns: [
            {data: "className"},
            {data: "classTcId"},
            {data: "createTime"},
            {
                data: "id",
                orderable: false, // 禁用排序
                defaultContent: "",
                // width: "10%",
                render: function (data, type, row, meta) {
                    return data = '<a class="btn btn-default btn-sm" id="edit"><i class="fa fa-pencil"></i>编辑</a>  ' +
                        '<a class="btn  btn-danger btn-sm" id="del"><i class="fa fa-trash-o"></i>删除</a>';
                }
            }
        ]
    });

    $('#example2 tbody').on('click', 'a#edit', function () {
        var data = $('#example2').DataTable().row($(this).parents('tr')).data();
        alert(data.id)
    });

    // Order by the grouping
    $('#example2 tbody').on('click', 'tr.group', function () {
        var currentOrder = table.order()[0];
        if (currentOrder[0] === 2 && currentOrder[1] === 'asc') {
            table.order([2, 'desc']).draw();
        } else {
            table.order([2, 'asc']).draw();
        }
    });

    $.fn.isValid = function () {
        return this[0].checkValidity()
    }
})